<?php
namespace app\user\controller;

use app\common\controller\Front;

class Signup extends Front
{
    public function index()
    {
        if($this->user['user_id']){
            return $this->redirect('user/index/index');
        }

        $this->assign($this->site);
        
        return $this->fetch();
    }
    
    public function update()
    {
        $post = [];
        $post['user_mobile']  = input('post.user_mobile/s');
        $post['user_pass']    = input('post.user_pass/s');
        $post['user_captcha'] = input('post.user_captcha/d');
        //验证输入
        $modelUser = model('common/User','loglic');
        if(!$modelUser->registerValidate($post)){
            $this->error($modelUser->getError());
        }
        //验证短信码或安全码
        if(config('user.code')){
            $model = model('common/Captcha','loglic');
            if(!$model->check($post)){
                $this->error($model->getError());
            }
        }else{
            if(!captcha_check(input('post.captcha_image/d'))){
                $this->error('安全码错误');
            };
        }
        //调用注册接口
        if(!$modelUser->registerMobile($post['user_mobile'],$post['user_pass'])){
            $this->error($modelUser->getError());
        }
        //注册成功
        $this->success('ok',dcUrlRedirect());
    }
}